;(function () {
    let $modal = $('#user-log-modal')
    let $infoTable = $modal.find('#info-table')
    let $requestTable = $modal.find('#request-table')
  
    let $viewSpan = $('.log-view')
  
    let fnTrigger = () => {
      $viewSpan.click(function () {
        console.log(1)
        let $this = $(this)
        let data = {
          id: $this.attr('data-id'),
          user_id: $this.attr('data-user-id'),
          user_name: $this.attr('data-user-name'),
          rid: $this.attr('data-rid'),
          ip: $this.attr('data-ip'),
          create_time: $this.attr('data-create-time'),
          title: $this.attr('data-title'),
          url: $this.attr('data-url')
        }
        let request = $this.attr('data-request')
        try {
          request = $.parseJSON(request)
        } catch(e) {
          request = {}
        }
        fnInitTable($infoTable, data)
        fnInitTable($requestTable, request)
      })
    }
  
    let fnInitInfoTable = (data) => {
      $tbody = $infoTable.find('tbody')
      $tbody.children().remove()
      $trs = $('')
      for (let key in data) {
        $trs.append('<tr><td>' + key + '</td><td>' + data[key] + '</td></tr>')
      }
      $infoTable.append($trs)
    }
  
    let fnInitRequestTable = (data) => {
      $tbody = $requestTable.find('tbody')
      $tbody.children().remove()
      $trs = $('')
      for (let key in data) {
        $trs.append('<tr><td>' + key + '</td><td>' + data[key] + '</td></tr>')
      }
      $requestTable.append($trs)
    }
  
    let fnInitTable = function ($table, data) {
      // $tbody = $table.find('tbody')
      // $tbody.children().remove()
      $table.children('tbody').remove();
      $trs = $('<tbody></tbody>')
      for (let key in data) {
        $trs.append('<tr><td>' + key + '</td><td>' + data[key] + '</td></tr>')
      }
      console.log($trs)
      // $tbody.append($trs)
      $table.append($trs)
    }
  
    fnTrigger()
  })()
  